package com.wjc.train.member.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import com.wjc.train.member.req.PassengerQueryReq;
import com.wjc.train.member.req.PassengerSaveReq;
import com.wjc.train.member.resp.PassengerQueryResp;
import com.wjc.train.member.service.IPassengerService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 乘车人表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-07-26
 */
@Validated
@RestController
@RequestMapping("/passenger")
public class PassengerController {

    @Resource
    private IPassengerService passengerService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid PassengerSaveReq passengerSaveReq){
        passengerService.save(passengerSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp queryList(@RequestBody PassengerQueryReq passengerQueryReq){
        IPage<PassengerQueryResp> iPage =
                passengerService.queryList(PageUtil.getPage(passengerQueryReq.getQueryPage()), passengerQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        passengerService.delete(id);
        return CommonResp.success();
    }

    /**
     * 查询当前用户的乘车人信息
     * @return
     */
    @GetMapping("/query-mine")
    public CommonResp save(){
        return CommonResp.success(passengerService.queryMine());
    }
}
